package com.cro.prison.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cro.prison.entity.dto.DailyBehaviorDto;
import com.cro.prison.entity.pojo.DailyBehavior;
import com.cro.prison.entity.pojo.Depart;
import com.cro.prison.entity.pojo.User;
import com.cro.prison.entity.vo.BehaviorCountVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.sql.Date;
import java.util.List;

/**
 * @author augus
 * @create 2022-11-22-14:19
 */
@Mapper
public interface DailyBehaviorDao extends BaseMapper<DailyBehavior> {
    @Select( " select * FROM daily_behavior as db WHERE (db.person_id = #{personId} AND db.create_time <= #{endDate} AND db.create_time >= #{beginDate})")
    List<DailyBehavior> getDailyBehavior(@Param("personId")Long personId, @Param("beginDate")Date beginDate, @Param("endDate")Date endDate);

    List<DailyBehavior> listAll();

    List<DailyBehaviorDto> countDailyBehavior(@Param(value = "personId")Long personId,@Param(value = "type")Integer type);

    @Select( " select * FROM daily_behavior as db WHERE (db.create_time <= #{endDate} AND db.create_time >= #{beginDate})")
    List<DailyBehavior> getAllDailyBehavior( @Param("beginDate")Date beginDate, @Param("endDate")Date endDate);

    @Select("SELECT d.abnormal_behavior_type type,count(*) count FROM daily_behavior d  WHERE d.person_id in(SELECT p.id FROM `prisoner` p where p.type = #{type})GROUP BY d.abnormal_behavior_type;")
    List<BehaviorCountVo> seletByType(@Param("type") Integer prisonerType);
    @Select("SELECT d.abnormal_behavior_type type,count(*) count FROM daily_behavior d  WHERE d.person_id in (#{ids}) GROUP BY d.abnormal_behavior_type;")
    List<BehaviorCountVo> seletByPersonIds(@Param("ids") String ids);
    @Select("SELECT d.abnormal_behavior_type type,count(*) count FROM daily_behavior d GROUP BY d.abnormal_behavior_type;")
    List<BehaviorCountVo> selectAllBehaviorCount();
}
